package com.member;
import java.util.ArrayList;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class GradeDAO{
	String driver = "oracle.jdbc.driver.OracleDriver";
	String url ="jdbc:oracle:thin:@211.183.2.30:1521:orcljava";
	String uid ="java21";
	String pw ="java21";
	
	public GradeDAO(){
		try{Class.forName(driver);
		} catch{ClassNotFoundException e{
			e.printStackTrace();
		}		
}
		public ArrayList<GradeDTO> select(){
			ArrayList<GradeDTO> list = new ArrayList<bradeDTO>();
			Connection con = null;
			PreparedStatement pstmt =null;
			ResultSet rs = null;
			
			try{
				con =DriverManager.getConnection(url,uid,pw);
				String sql = "select gno, gname from grade order by gno asc";
				pstmt= con.prepareStatement(sql);
				rs = pstmt.executeQuery();
			
			while(rs.next()){
				GradeDTO dto = new GradeDTO();
				dto.setGno(rs.getInt("gno"));
				dto.setGname(rs.getString("gname"));
				list.add(dto);
				
//				System.out.println(dto.getGno()+" "+dto.getGname());
			    }
			}catch(Exception e){
				e.printStackTrace();
			}finally{
				try(if(rs!=null)rs.close();
				try(pstm)
					
				}
			}
			}
			
		}
}
	